package com.ruoyi.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductPlan;
import com.ruoyi.product.service.IProductPlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计划执行Controller
 * 
 * @author ruoyi
 * @date 2023-02-10
 */
@Controller
@RequestMapping("/product/plan")
public class ProductPlanController extends BaseController
{
    private String prefix = "product/plan";

    @Autowired
    private IProductPlanService productPlanService;

    @RequiresPermissions("product:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询计划执行列表
     */
    @RequiresPermissions("product:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductPlan productPlan)
    {
        startPage();
        List<ProductPlan> list = productPlanService.selectProductPlanList(productPlan);
        return getDataTable(list);
    }

    /**
     * 导出计划执行列表
     */
    @RequiresPermissions("product:plan:export")
    @Log(title = "计划执行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductPlan productPlan)
    {
        List<ProductPlan> list = productPlanService.selectProductPlanList(productPlan);
        ExcelUtil<ProductPlan> util = new ExcelUtil<ProductPlan>(ProductPlan.class);
        return util.exportExcel(list, "计划执行数据");
    }

    /**
     * 新增计划执行
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存计划执行
     */
    @RequiresPermissions("product:plan:add")
    @Log(title = "计划执行", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductPlan productPlan)
    {
        return toAjax(productPlanService.insertProductPlan(productPlan));
    }

    /**
     * 修改计划执行
     */
    @RequiresPermissions("product:plan:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductPlan productPlan = productPlanService.selectProductPlanById(id);
        mmap.put("productPlan", productPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存计划执行
     */
    @RequiresPermissions("product:plan:edit")
    @Log(title = "计划执行", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductPlan productPlan)
    {
        return toAjax(productPlanService.updateProductPlan(productPlan));
    }

    /**
     * 删除计划执行
     */
    @RequiresPermissions("product:plan:remove")
    @Log(title = "计划执行", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productPlanService.deleteProductPlanByIds(ids));
    }
}
